package ControlLayer;
import ModelLayer.*;
import java.util.ArrayList;
//model layer package has to be imported

/**
 * Controller class for the address book
 * 
 * @author (kbh) 
 * @version (2005.03.31)
 * (FEN): 2006.03.21: Some changes to the architecture in order to assure layering
 *                    and loose coupling
 */
public class AddressCtr
{
    
    //declare instance variables to reference containers
    private AddressBook addressBook;
    
    
    public AddressCtr()
    {
        addressBook = addressBook.getInstance();
    }
    
    //Dummy implementation: after implementing the model layer 
    //objects of class Person are to be returned, not String
    public Person getPerson(long id)
    {
        
        //with an id-number equal to the parameter id
        //when person is found, the method is to call print-methods in the TUI layer
        Person person = addressBook.findContact(id);
        return person;
    }
    
    
    public void createPerson(long id, String name, String address, String postalCode, String city, String phone)
    {   
       //creates a Person object and stores it in the container
       Person p = new Person(id , name , address , postalCode , city , phone);
       addressBook.addContact(p);
    }
    
    public void deletePerson(long id)
    {
        //search for the person and delete the object from the container
        addressBook.deleteContact(id);
    }
    
    public void updatePerson(long searchID, long rID, String name, String address, String postalCode, String city, String phone)
    {
        long search = searchID;
        Person person = addressBook.findContact(search);
        if(person!=null)
        {
            Person replace = new Person(rID, name , address, postalCode, city, phone);
            addressBook.updateContact(searchID,rID, name , address, postalCode, city, phone);
            
        }

    }
    
    public ArrayList<Person> listAllPersons()
    {
          return addressBook.getList();
    }
    public int size()
    {
        return addressBook.size();
    }
    public Person get(int x)
    {
        return addressBook.get(x);
    }
    public int check(long search)
    {
        return addressBook.check(search);
    }
    public void addLoan(long id, long loanID, String loanDate, String loanPeriod)
    {
        addressBook.addLoan(id, loanID, loanDate, loanPeriod);
    }
}
